<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商品详情</title>
    <link rel="stylesheet" href="../../css/api.css" />
    <link rel="stylesheet" href="../../css/aui.css" />
    <link rel="stylesheet" href="../../css/common.css" />
    <link rel="stylesheet" href="../../css/detail.css">
    <link rel="stylesheet" href="../../css/font/iconfont.css">
</head>

<body>
    <section>
        <div class="m-slider" data-ydui-slider>
            <div class="slider-wrapper">
                <div class="slider-item">
                    <img id="img" src="">
                </div>
            </div>
            <div class="slider-pagination"></div>
        </div>
        <div class="title">
            <h2><span id="name"></span><span class="share">分享</span></h2>
        </div>

        <div class="title">
            <div class="tit">
                <span class="tit-left">需求</span>
                <span id="demand" class="tit-content"></span>
            </div>
            <div class="aui-hr"></div>
            <div class="tit">
                <span class="tit-left">标签</span>
                <span id="tag" class="tit-content red"></span>
            </div>
            <div class="aui-hr"></div>
            <div class="tit">
                <span class="tit-left">价格</span>
                <span id="val" class="tit-content red"></span>
            </div>
            <div class="aui-hr"></div>
            <div class="tit">
                <span class="tit-left">数量</span>
                <span id="amount" class="tit-content"></span>
            </div>
        </div>

        <div class="block">
            <div class="sm1">置换品详情</div>
            <div class="aui-hr"></div>
            <div class="introduc">
              <p id="content"></p>
            </div>
            <div class="aui-hr"></div>
            <div class="sm3" id="ct">
              <!-- <p><img src="../../image/detail02.jpg"></p> -->
            </div>
        </div>
    </section>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/zepto.js"></script>
<script src="../../script/common.js"></script>
<script>
    var id = '';

    apiready = function() {
        id = api.pageParam.id;
        var d = {
            id: id,
            code: ''
        }
        showProgress();

        $.ajax({
            url: "http://www.aiyi5.com/getGoodsInfoForDetail",
            type: "POST",
            async: false,
            data: d,
            dataType: 'json',
            error: function(errorMsg) {
              hideProgress();
              toast(errorMsg);
            },
            success: function(data) {
                $('#name').html(data.goods.name);
                $('#amount').html(data.goods.amount);
                $('#val').html(data.goods.val);
                $('#content').html(data.goods.content.replace('\n', '</p><p>'));
                $('#img').attr('src', 'http://www.aiyi5.com/resource/goods/' + data.goods.img);
                var demand = '';
                $.each(data.demand, function(n, v) {
                    if (demand != '') {
                        demand += '/';
                    }
                    demand += v.name;
                });
                $('#demand').html(demand);

                $('#tag').empty();
                $.each(data.goods.tags.split(','), function(n1, v1) {
                    var temp = '<li pt="221" t="2" class="focr2 comm2">';
                    temp += '<a>' + v1 + '</a><b></b></li>';
                    //$('#tag').append(temp);
                });

                $('#ct').empty();
                $.each(data.img, function(n1, v1) {
                    var temp = '<p><img src="http://www.aiyi5.com/resource/goods/' + v1.img + '"></p>';
                    $('#ct').append(temp);
                });
                isCollect();

                hideProgress();
            }
        });
    }

    function showLinkTest() {
        if ($('#userTitle').html() === '') {
          openWin('login_header')
          // window.location.href = 'login.html?backurl=' + window.location.href;
        } else {
            $.ajax({
                url: "getLinkTest",
                type: "POST",
                async: false,
                data: d,
                dataType: 'json',
                error: function(errorMsg) {

                },
                success: function(data) {
                    if (data.code == '0') {
                        getLink();
                        return;
                    }
                    if (data.code == '2') {
                        layer.alert(data.msg);
                        return;
                    }
                    layer.confirm('查看联系方式将会扣除一个可查看信息数量，当前可查看信息数量：' + data.msg + '，确定要查看吗？', {
                        btn: ['确定', '取消'] //按钮
                    }, function() {
                        layer.close(layer.index);
                        getLink();
                    }, function() {

                    });
                }
            });
        }
    }

    function getLink() {
        $.ajax({
            url: "getLink",
            type: "POST",
            async: false,
            data: d,
            dataType: 'json',
            error: function(errorMsg) {

            },
            success: function(data) {
                if (data.tele == '') {
                    layer.alert('获取失败');
                    return;
                }
                $('#linker').html(data.linker);
                $('#tele').html(data.tele);
                $('#address').html(data.address);

                var bh = $("body").height();
                var bw = $("body").width();
                $(".fullbg").css({
                    height: bh,
                    width: bw,
                    display: "block"
                });
                $(".upload-dialog").show();
            }
        });
    }

    function addCollect() {
        var d = {
            id: id
        }
        $.ajax({
            url: "http://www.aiyi5.com/insertCollect",
            type: "POST",
            async: false,
            data: d,
            dataType: 'json',
            error: function(errorMsg) {

            },
            success: function(data) {
                alert(data.msg);
            }
        });
    }

    function isCollect() {
        var d = {
            id: id,
        }
        $.ajax({
            url: "http://www.aiyi5.com/isCollect",
            type: "POST",
            async: false,
            data: d,
            dataType: 'json',
            error: function(errorMsg) {

            },
            success: function(data) {
                if (data.code === '0') {

                }
            }
        });
    }

    function closeLink() {
        $(".fullbg").hide();
        $(".upload-dialog").hide();
    }
</script>

</html>
